from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    email = db.Column(db.String(20), nullable=False)
    tel = db.Column(db.String(15), nullable=True)
    cts = db.Column(db.BigInteger, default=0)
    active = db.Column(db.Boolean, default=False)
    nickname = db.Column(db.String(20), default='游客')
    gender = db.Column(db.Integer, default=0)
    avater = db.Column(db.String(255), default='https://profile.csdnimg.cn/D/3/A/0_weixin_63576473')
    birth = db.Column(db.Time, nullable=True)
    level = db.Column(db.Integer, nullable=False, default=1)
    salt = db.Column(db.String(255), nullable=True)

    def json(self):
        return {"id": self.id, "username": self.username, "email": self.email}


